﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="add_Comment_Reply.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Lesson.add_Comment_Reply" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<body>
    <%
        var cmt = new TblLessonCommentController().FetchAll().Where(x => x.Id == this.id).Single();
        var get_user_cmt = new TblUserController().FetchAll().Where(x => x.UserId == cmt.UserId).Single();
        var get_reply = new TblLessonCommentReplyController().FetchAll().Where(x => x.CmtId == this.id);
    %>
    <div class="faq-avatar w3-col">
        <img src="../Content/avatar/<%=get_user_cmt.Avatar %>" class="w3-circle" />
    </div>
    <div class="faq-content w3-col">
        <%if (get_user_cmt.UserLevel != 5)
          { %>
        <span class="faq-user"><%=get_user_cmt.FullName %> :</span>&nbsp;<span class="cmt_Content"><%=cmt.CmtContent %></span><%}
          else
          { %>
        <span class="faq-user w3-text-red"><%=get_user_cmt.FullName %> :</span>&nbsp;<span class="cmt_Content"><%=cmt.CmtContent %></span>
        <%} %><br />

        <div class="w3-small w3-padding-bottom">
            <%if (Session["user_id"] != null)
              {%><a onclick="answer_btn(event)" class="faq-answer-btn faq-text-btn">Trả lời</a>
            <%if (Session["level"].ToString() == "5")
              { %><a onclick="pin_btn(<%=cmt.Id %>)" <%if (cmt.CmtPin == true)
                                                       { %>style="display:none" <%} %> class="faq-ghim-btn faq-text-btn">Ghim</a>
            <a onclick="unpin_btn(<%=cmt.Id %>)" <%if (cmt.CmtPin == true)
                                                   { %>style="display:inline-block"
                <%} %> class="faq-unghim-btn faq-text-btn">Bỏ ghim</a><%}
              }
              else
              { %><a onclick="authentication()" class="faq-answer-btn faq-text-btn">Trả lời</a><%} %><span class="faq-time w3-text-grey"><%if (cmt.CmtEdit == false)
                                                                                                                                             { %>Đã đăng - <%}
                                                                                                                                             else
                                                                                                                                             { %>Đã chỉnh sửa - <%} %><%=datetimeToString(cmt.CmtDate.ToString()) %></span>
        </div>
        <div class="faq-answer-content">
            <%if (get_reply.ToList().Count != 0)
              { %>
            <div style="display:none" class="nut-hien w3-small w3-padding-bottom"><a onclick="show_answer(event)" class="faq-show-older-answer-btn faq-text-btn">Xem <%=get_reply.ToList().Count %> câu trả lời trước&nbsp;<i class="fa fa-angle-down"></i></a></div>
            <div style="display:block" class="nut-an w3-small w3-padding-bottom"><a onclick="hide_answer(event)" class="faq-hide-older-answer-btn faq-text-btn">Ẩn <%=get_reply.ToList().Count %> câu trả lời trước&nbsp;<i class="fa fa-angle-up"></i></a></div>
            <%} %>
            <ul class="faq-answer-list faq-teacher-reply" style="display:none">
                <%if (findReplyTeacher(cmt.Id) != null)
                  {
                      var get_teacher_reply = new TblLessonCommentReplyController().FetchAll().Where(x => x.Id == findReplyTeacher(cmt.Id)).Single();
                      var get_teacher = new TblUserController().FetchAll().Where(x => x.UserId == get_teacher_reply.UserId).Single();
                %>
                <li class="w3-row reply_<%=get_teacher_reply.Id %>">
                    <div class="faq-answer-avatar w3-col">
                        <img src="../Content/avatar/<%=get_teacher.Avatar %>" class="w3-circle" />
                    </div>
                    <div class="faq-content w3-col l10">
                        <div class="faq-answer-content-edit">
                            <input type="text" value="<%=get_teacher_reply.CmtContent %>" placeholder="Viết trả lời..." autofocus="autofocus" />
                        </div>
                        <div class="faq-answer-content"><span class="faq-user w3-text-red"><%=get_teacher.FullName %> :</span>&nbsp;<span><%=get_teacher_reply.CmtContent %></span></div>
                        <div class="w3-small">
                            <%if (Session["user_id"] != null)
                              { %><%if (int.Parse(Session["user_id"].ToString()) == get_teacher_reply.UserId)
                                    { %><a class="faq-edit-answer-btn faq-text-btn">Chỉnh sửa</a><a class="faq-cancel-edit-answer-btn faq-text-btn">Hủy</a><a class="faq-delete-btn faq-text-btn">Xóa</a><%}
                              } %><span class="faq-time w3-text-grey"><%=datetimeToString(get_teacher_reply.CmtDate.ToString()) %></span>
                        </div>
                    </div>
                </li>
                <%} %>
            </ul>
            <ul class="faq-answer-list faq-older-answer" style="display:block">
                <%foreach (TblLessonCommentReply reply in get_reply)
                  {
                      var get_user_reply = new TblUserController().FetchAll().Where(x => x.UserId == reply.UserId).Single();
                %>
                <li class="w3-row reply_<%=reply.Id %>">
                    <div class="faq-answer-avatar w3-col">
                        <img src="../Content/avatar/<%=get_user_reply.Avatar %>" class="w3-circle" />
                    </div>
                    <div class="faq-content w3-col l10">
                        <div class="faq-answer-content-edit">
                            <input type="text" id="txt_answer_edit_<%=reply.Id %>" onblur="clear_edit();clear_input()" onclick="edit_answer(<%=reply.Id%>);get_input(<%=cmt.Id%>)" value="<%=reply.CmtContent %>" placeholder="Viết trả lời..." autofocus="autofocus" />
                        </div>
                        <div class="faq-answer-content">
                            <%if (get_user_reply.UserLevel != 5)
                              { %><span class="faq-user"><%=get_user_reply.FullName %> :</span><%}
                              else
                              { %><span class="faq-user w3-text-red"><%=get_user_reply.FullName %> :</span><%} %>&nbsp;<span class="cmt_Content"><%=reply.CmtContent %></span>
                        </div>
                        <div class="w3-small">
                            <%if (Session["user_id"] != null)
                              { %><%if (Session["user_id"].ToString() == reply.UserId.ToString())
                                    {%><a class="faq-edit-answer-btn faq-text-btn">Chỉnh sửa</a><a class="faq-cancel-edit-answer-btn faq-text-btn">Hủy</a><a class="faq-delete-btn faq-text-btn">Xóa</a><%}
                              }%><span class="faq-time w3-text-grey"><%=datetimeToString(reply.CmtDate.ToString()) %></span>
                        </div>
                    </div>
                </li>
                <%} %>
            </ul>
            <%if (Session["user_id"] != null)
              {
                  var user = new TblUserController().FetchAll().Where(x => x.UserId == int.Parse(Session["user_id"].ToString())).Single();
            %>
            <ul class="faq-answer-list">
                <li class="faq-answer-row w3-row">
                    <div class="faq-answer-avatar w3-col">
                        <img src="../Content/avatar/<%=user.Avatar %>" class="w3-circle" />
                    </div>
                    <div class="faq-answer-input w3-col l10">
                        <input type="text" class="txt_answer" onblur="clear_input()" onclick="get_input(<%=cmt.Id%>)" placeholder="Viết trả lời..." />
                    </div>
                </li>
            </ul>
            <%} %>
        </div>
    </div>
    <div class="faq-action w3-center">
        <%if (cmt.CmtPin == false)
          { %>
        <i class="faq-ghim-sign faq-ghim-sign-hide fa fa-bookmark w3-text-deep-orange"></i>
        <%}
          else
          { %>
        <i class="faq-ghim-sign faq-ghim-sign-show fa fa-bookmark w3-text-deep-orange"></i>
        <%} %>
        <%if (Session["user_id"] != null)
          { %>
        <%if (Session["level"].ToString() == "5" || Session["user_id"].ToString() == cmt.UserId.ToString())
          { %>
        <div class="dropdown">
            <i data-toggle="dropdown" class="faq-option-btn fa fa-angle-down dropdown-toggle" title="Tùy chọn"></i>
            <div class="dropdown-menu dropdown-menu-right">
                <ul class="faq-option-list">
                    <li onclick="edit_cmt(<%=cmt.Id %>)"><a href="javascript:;"><i class="fa fa-edit"></i>&nbsp;Chỉnh sửa</a></li>
                    <li onclick="del_cmt(<%=cmt.Id %>)"><a href="javascript:;"><i class="fa fa-trash"></i>&nbsp;Xóa</a></li>
                </ul>
            </div>
        </div>
        <%}
          } %>
    </div>
</body>
</html>
